package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.escool.model.TbSedeHasPersonal;
import com.escool.model.VwPersonalSede;
@Repository
public class SedeHasPersonalDAOImpl implements SedeHasPersonalDAO {

	@Autowired
	SessionFactory sessionFactoyr;
	
	@Override
	public void addTbSedeHasPersonal(TbSedeHasPersonal TbSedeHasPersonal) {
		// TODO Auto-generated method stub
		sessionFactoyr.getCurrentSession().save(TbSedeHasPersonal);
	}

	@Override
	public void editTbSedeHasPersonal(TbSedeHasPersonal TbSedeHasPersonal) {
		// TODO Auto-generated method stub
		sessionFactoyr.getCurrentSession().update(TbSedeHasPersonal);	
	}

	@Override
	public void delTbSedeHasPersonal(int id) {
		// TODO Auto-generated method stub
		TbSedeHasPersonal cobro = (TbSedeHasPersonal) sessionFactoyr.getCurrentSession().load(TbSedeHasPersonal.class,id);
		if(cobro != null){
			sessionFactoyr.getCurrentSession().delete(cobro);
		}
	}

	@Override
	public List<TbSedeHasPersonal> listTbSedeHasPersonal() {
		// TODO Auto-generated method stub
		String hql = "from TbSedeHasPersonal";
		return sessionFactoyr.getCurrentSession().createQuery(hql).list();
	}

	@Override
	public TbSedeHasPersonal findTbSedeHasPersonal(int id) {
		// TODO Auto-generated method stub
		return (TbSedeHasPersonal)sessionFactoyr.getCurrentSession().get(TbSedeHasPersonal.class, id);
	}

	@Override
	public List<VwPersonalSede> listVwPersonalSede() {
		// TODO Auto-generated method stub
		String hql = "from VwPersonalSede";
		return sessionFactoyr.getCurrentSession().createQuery(hql).list();
	}

}
